<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  header("location:checklogin.php");
}

$loadDetailArray = 0;
$i=0;
$billType="";
$totalWeight = 0;
$totalAll          = 0 ;
$loadingInvoiceId = (isset($_REQUEST['loadingInvoiceId'])) ? $_REQUEST['loadingInvoiceId'] : 0;
$loadDetailArray = array();
$selectParty = "SELECT loadingInvoiceId,loadingInvoiceDetailId,billType,lrNo,lrDate,qty,discription,consignor,consignee,weight,toPay,remarks,lrAmount
                  FROM loadinginvoicedetail 
                 WHERE loadingInvoiceId = ".$loadingInvoiceId."";
$selectPartyRes = mysql_query($selectParty);
while($loadRow = mysql_fetch_array($selectPartyRes))
{
	$loadDetailArray[$i]['loadingInvoiceId']        = $loadRow['loadingInvoiceId'];
	$loadDetailArray[$i]['loadingInvoiceDetailId']  = $loadRow['loadingInvoiceDetailId'];
	$loadDetailArray[$i]['lrNo']                    = $loadRow['lrNo'];
	$loadDetailArray[$i]['billType']                = $loadRow['billType'];
	$loadDetailArray[$i]['lrDate']                  = $loadRow['lrDate'];
	$loadDetailArray[$i]['qty']                     = $loadRow['qty'];
	$loadDetailArray[$i]['discription']             = $loadRow['discription'];
	$loadDetailArray[$i]['consignor']               = $loadRow['consignor'];
	$loadDetailArray[$i]['consignee']               = $loadRow['consignee'];
	$loadDetailArray[$i]['weight']                  = $loadRow['weight'];
	$loadDetailArray[$i]['toPay']                   = $loadRow['toPay'];
	$loadDetailArray[$i]['remarks']                 = $loadRow['remarks'];
	$loadDetailArray[$i]['lrAmount']                = $loadRow['lrAmount'];
	$totalAll                                      += $loadRow['weight'];
	$i++;
}

$j=0;
$loadingArray = array();
$selectLoadingInvoice = "SELECT loadingInvoiceId,invoiceNo,DATE_FORMAT(invoiceDate,'%d-%m-%Y') AS invoiceDate,fromTable.branchName AS fromName ,
                                toTable.branchName AS toName,totalWeight,truckmaster.truckNo
                                  FROM loadinginvoice
                                  LEFT JOIN branch AS fromTable ON fromTable.branchId = loadinginvoice.fromId
                                  LEFT JOIN branch AS toTable   ON toTable.branchId = loadinginvoice.toId
                                  LEFT JOIN truckmaster ON truckmaster.truckId = loadinginvoice.truckId
                                  WHERE loadingInvoiceId = ".$loadingInvoiceId."";
  $selectLoadingInvoiceRes = mysql_query($selectLoadingInvoice);
  while($loadingRow = mysql_fetch_array($selectLoadingInvoiceRes))
  {
    $loadingArray[$j]['loadingInvoiceId']  = $loadingRow['loadingInvoiceId'];
    $loadingArray[$j]['fromName']          = $loadingRow['fromName'];
    $loadingArray[$j]['toName']            = $loadingRow['toName'];
    $loadingArray[$j]['truckNo']           = $loadingRow['truckNo'];
    $loadingArray[$j]['invoiceNo']         = $loadingRow['invoiceNo'];
    $loadingArray[$j]['invoiceDate']       = $loadingRow['invoiceDate'];
    $totalWeight                           = $loadingRow['totalWeight'];
    $j++;
  }
include("./bottom.php");
$smarty->assign("loadDetailArray",$loadDetailArray);
$smarty->assign('totalWeight',$totalWeight);
$smarty->assign("totalAll",$totalAll);
$smarty->assign('loadingArray',$loadingArray);
$smarty->assign('billType',$billType);
$smarty->display("loadingDetail.tpl");
?>